package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-03-02
 * Time: 00:26
 */
class Test1{}
class Student{}

public class Thread_Safe_One {
    public static long count = 0L;

    public static void main(String[] args) throws InterruptedException {
        Test1 test = new Test1();
        Student student = new Student();
        Thread thread1 = new Thread(()->{
            for (int i = 1; i <= 50000; i++) {
                synchronized (test) {
                    count++;
                }
            }
        });
        Thread thread2 = new Thread(()->{
            for (int i = 1; i <= 50000; i++) {
                synchronized (student) {
                    count++;
                }
            }
        });

        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();

        System.out.println("count = " + count);
    }
}
